﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       // Response.Write("Date : "+Request.QueryString["dd"].ToString()+"<br>Month : "+Request.QueryString["mm"].ToString()+"<br>Year : "+Request.QueryString["yy"].ToString());
        getcalender(Request.QueryString["dd"].ToString(), Request.QueryString["mm"].ToString(), Request.QueryString["yy"].ToString());
    }

    void getcalender(string ddd,string mmm,string yyy)
    {
        
        int n = 0;
        string currenttd = "";
        string dd = ddd;// Request.QueryString["dd"].ToString();
        string mm =mmm;// Request.QueryString["mm"].ToString();//0-11
        string yy = yyy;// Request.QueryString["yy"].ToString();
        DateTime da = new DateTime(Convert.ToInt16(yy), Convert.ToInt16(mm)+1, 1);
        //string xx = da.DayOfWeek.ToString();
        yearmonth.InnerHtml = "<u><b>" + da.ToString("MMMM") + " - " + yy + "</b></u>";
        int zz = Convert.ToInt16(da.DayOfWeek);//0-6
        if (mm == "0" || mm == "2" || mm == "4" || mm == "6" || mm == "7" || mm == "9" || mm == "11")
        {
            n = 31;
        }
        else
        {

            if (mm == "1" && ((Convert.ToInt16(yy) % 4) == 0))
            {
                n = 29;
            }
            else
            {
                n = 28;
            }
            if (mm != "1")
            {
                n = 30;
            }
        }

       
        int count = 1;
        int temp = 0;
        if (zz == 0)
        {
            temp = 7;
        }
        else
        {
            temp = zz;
        }
        
        for (int i = 1; i <= 5; i++)
        {
            
            for (int j=temp; j <= 7; j++)
            {
                //if (count < n && i == 5 && j == 7)
                //{
                //    i = 1;
                //    j = 1;

                //}
                
               
               
                if (count > n)
                {
                    j = 8;
                    i = 6;
                }

                else
                {
                    currenttd = "Td" + i + j;
                    HtmlTableCell d = (HtmlTableCell)Page.FindControl(currenttd);
                    d.InnerText = "" + count;
                    if ("" + count == dd)
                    {
                        HtmlTableCell today = (HtmlTableCell)Page.FindControl(currenttd);
                        today.Attributes.Add("class", "now");
                    }
                    if (count < n && i == 5 && j == 7)
                    {
                        i = 1;
                        j = 0;
                        
                    }
                
                    count++;
                  
                }

               
                
                
            }
           temp = 1;
          
        }
        
        
        
        
        
        
        //int num=12;
        //string xxx = "Td" + num;
        //HtmlTable td = new HtmlTable();
        //HtmlTableCell d = (HtmlTableCell)Page.FindControl(xxx);
        //d.Attributes.Add("class", "now");
        

    }
}